package com.bd.learning.excel;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.ArrayList;
import java.util.List;

public class ExcelTool {


    public static void main(String[] args) {
        ExcelTool et = new ExcelTool();
        List<BeanObj> totalList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\SMCP对外类汇总.xlsx",2);
        List<BeanObj> aqList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\安全管理-付兴乐.xlsx",2);
        List<BeanObj> reportList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\报表管理-王萌.xlsx",2);
        List<BeanObj> alarmList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\告警管理-熊梦飞.xlsx",2);
        List<BeanObj> baseConfList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\基础配置-付兴乐.xlsx",2);
        List<BeanObj> baseChanelList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\基础通道-付兴乐.xlsx",2);
        List<BeanObj> monitorList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\监管中心-蒙秋敏.xlsx",2);
        List<BeanObj> dbList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\数据库转储-张兴伦.xlsx",2);
        List<BeanObj> txList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\通信管理-张合.xlsx",2);
        List<BeanObj> pmCurrentList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\性能管理-史红艳.xlsx",2);
        List<BeanObj> pmHisList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\性能管理-向乐.xlsx",2);
        List<BeanObj> bussList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\业务管理-刘丹.xlsx",2);
        List<BeanObj> busList = et.getBeanObj("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\总线微服务-刘洋.xlsx",2);

        System.out.println(totalList.size()+"|"+aqList.size());
        et.clearSame(totalList,aqList);
        et.clearSame(totalList,reportList);
        et.clearSame(totalList,alarmList);
        et.clearSame(totalList,baseConfList);
        et.clearSame(totalList,baseChanelList);
        et.clearSame(totalList,monitorList);
        et.clearSame(totalList,dbList);
        et.clearSame(totalList,txList);
        et.clearSame(totalList,pmCurrentList);
        et.clearSame(totalList,pmHisList);
        et.clearSame(totalList,bussList);
        et.clearSame(totalList,busList);
        System.out.println(totalList.size());

        ExcelWriter writer = ExcelUtil.getWriter("D:\\doc\\测试覆盖率\\测试代码覆盖率提升\\t2.xlsx");
        writer.write(totalList,true);
        writer.close();

    }

    public void clearSame(List<BeanObj> totalList ,List<BeanObj> other){
        for(BeanObj b : other){
            boolean flag = totalList.remove(b);
//            System.out.println(b);
        }
    }

    public List<BeanObj> getBeanObj(String file,int index){
        ExcelReader reader = ExcelUtil.getReader(FileUtil.file(file),index);
        List<List<Object>> readAll = reader.read();
        List<BeanObj> totalList = new ArrayList<>();

        int n = 0;
        StringBuffer sb = new StringBuffer();
        for (List<Object> list : readAll){
            BeanObj bo = new BeanObj();
            bo.setType1((String) list.get(0));
            bo.setType2((String) list.get(1));
            bo.setPackageName(String.valueOf(list.get(2)));
            bo.setFileName(String.valueOf(list.get(3)));
            bo.setMethodName(String.valueOf(list.get(4)));
            bo.setMethodNum(String.valueOf(list.get(5)));
            totalList.add(bo);
        }
        reader.close();
        return totalList;
    }


}
